package com.caocaog.market.controller;

import com.caocaog.market.entity.ShopDelivery;
import com.caocaog.market.service.ShopDeliveryService;
import com.caocaog.market.vo.ShopDeliveryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.GenericController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 店铺配送管理
 *
 * @author chechen
 * @date 2021-11-30
 */
@Slf4j
@RestController
@Api(value = "shopDelivery", tags = ShopDeliveryController.TABLE_MEANING)
@RequestMapping("/shopDelivery")
public class ShopDeliveryController extends GenericController<ShopDelivery, ShopDeliveryService> {

	public static final String TABLE_MEANING = "店铺配送管理";

	private static final String ADD = "店铺配送管理-添加";
	@AutoLog(value = ADD)
	@ApiOperation(value = ADD, notes = ADD)
	@PostMapping(value = "/add")
	@RequiresPermissions("shopDelivery:add")
	public Result<?> add(@RequestBody @Validated ShopDeliveryVO shopDeliveryVO) {
		return Result.OK(ADD_SUCCESS, super.service.addShopDelivery(shopDeliveryVO));
	}

	private static final String EDIT = "店铺配送管理-编辑";
	@AutoLog(value = EDIT)
	@ApiOperation(value = EDIT, notes = EDIT)
	@PutMapping(value = "/edit")
	@RequiresPermissions("shopDelivery:edit")
	public Result<?> edit(@RequestBody @Validated ShopDeliveryVO shopDeliveryVO) {
		super.service.updateShopDelivery(shopDeliveryVO);
		return Result.OK(EDIT_SUCCESS);
	}

	private static final String DELETE = "店铺配送管理-通过id删除";
	@AutoLog(value = DELETE)
	@ApiOperation(value = DELETE, notes = DELETE)
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name = "id") Long id) {
		return Result.OK(DELETE_SUCCESS, super.service.deleteShopDelivery(id));
	}

	private static final String DELETE_BATCH = "店铺配送管理-批量删除";
	@AutoLog(value = DELETE_BATCH)
	@ApiOperation(value = DELETE_BATCH, notes = DELETE_BATCH)
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name = "ids") String ids) {
		return Result.OK(DELETE_SUCCESS, super.service.deleteBatchShopDelivery(Arrays.asList(ids.split(","))));
	}

	private static final String BY_ID = "店铺配送管理-通过店铺id查询";
	@AutoLog(value = BY_ID)
	@ApiOperation(value = BY_ID, notes = BY_ID)
	@GetMapping(value = "/queryByShopId")
	@RequiresPermissions("shopDelivery:view")
	public Result<?> queryById(@RequestParam(name = "shopId") String shopId) {
		return Result.OK(super.service.queryShopDeliveryByShopId(shopId));
	}

}
